<?
        require_once('../inc/Users.php');
        require_once('../inc/Keywords.php');
        if(isset($_POST['id']))
        {
                $row = $_POST;
                $results = ValidateUser($row);
                if($results === true)
                        $results = SaveUser($row);
                if($results === true)
                {
                        if(isset($_REQUEST['ajax'])){
                                $rs = GetUser($row['id']);
                                include('item.php');
                        }else{
                                header("Location: index.php?inserted=$row[id]#inserted");
                        }
                        die();
                }
        }else{
                if(isset($_REQUEST['id']))
                        $row = GetUser($_REQUEST['id']);
                else
                        $row = BlankUser();
        }
        $keywords = GetKeywords();//GetUserTypes();
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Details of user: <?=$row['FirstName']?> <?=$row['LastName']?></title>
    <link rel="stylesheet" type="text/css" href="../inc/bootstrap.css">
    <style type="text/css" ">
        .error { color: red; }
    </style>
</head>

<body>
        <? include('../inc/header.php'); ?>
        <div class="container">
                        <? include('../inc/nav.php'); ?>
            <div id="contents">
                
                <dl class="error">
                        <? foreach ($results as $key => $value): ?>
                                                <dt><?=$key?></dt>
                                                <dd><?=$value?></dd>
                        <? endforeach; ?>
                </dl>
                
                <form class="form-horizontal" method="post" action="">
                        
                    <div class=" control-group">
                        <label class="control-label" for="FirstName">First Name:</label>
                        <div class="controls">
                            <input type="text" name="FirstName" id="FirstName" value="<?=$row['FirstName']?>" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="LastName">Last Name:</label>
                        <div class="controls">
                            <input type="text" name="LastName" id="LastName" value="<?=$row['LastName']?>" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="created_at">created_at:</label>
                        <div class="controls">
                            <input type="text" name="created_at" id="created_at" value="<?=$row['created_at']?>" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="updated_at">updated_at:</label>
                        <div class="controls">
                            <input type="text" name="updated_at" id="updated_at" value="<?=$row['updated_at']?>" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="Address1">Address 1:</label>
                        <div class="controls">
                            <input type="text" name="Address1" id="Address1" value="<?=$row['Address1']?>" />
                        </div>
                    </div>
					<div class="control-group">
                        <label class="control-label" for="Address2">Address 2:</label>
                        <div class="controls">
                            <input type="text" name="Address2" id="Address2" value="<?=$row['Address2']?>" />
                        </div>
                    </div><div class="control-group">
                        <label class="control-label" for="City">City:</label>
                        <div class="controls">
                            <input type="text" name="City" id="City" value="<?=$row['City']?>" />
                        </div>
                    </div><div class="control-group">
                        <label class="control-label" for="State">State:</label>
                        <div class="controls">
                            <input type="text" name="State" id="State" value="<?=$row['State']?>" />
                        </div>
                    </div>
					<div class="control-group">
                        <label class="control-label" for="ZipCode">Zip Code:</label>
                        <div class="controls">
                            <input type="text" name="ZipCode" id="ZipCode" value="<?=$row['ZipCode']?>" />
                        </div>
                    </div><div class="control-group">
                        <label class="control-label" for="Country">Country:</label>
                        <div class="controls">
                            <input type="text" name="Country" id="Country" value="<?=$row['Country']?>" />
                        </div>
                    </div>
					 </div>
					 <div class="control-group">
					 <input type="hidden" name="id" value="<?=$row['id']?>" />
					 </div>
					 <div class="control-group">
                            <input type="hidden" name="id" value="<?=$row['id']?>" />
                                <input class="btn btn-primary" type="submit" value="Save" />
                            <a href="./" class="cancel-link">Cancel</a>
                        </div>
                </form>
           </div>
       </div>
	   <script type="application/javascript" src="http://code.jquery.com/ui/1.9.1/jquery-ui.js">
           </script>
       <script type="application/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js">
           </script>
       <script type="text/javascript">
                        $(function(){
                                //$("#Keyword_id").val('<?=$row['Keyword_id']?>');
                                //$("input[type='date']").datepicker();
                                
                                $("form").validate({
                                        rules: {
                                                Keyword_id: { required: true }
                                        }
                                });
                                
                        });
           </script>

</body>
</html>